/* 1380. 矩阵中的幸运数 */
/**
 * @param {number[][]} matrix
 * @return {number[]}
 */
var luckyNumbers = function (matrix) {
    const row = matrix.length, col = matrix[0].length
    const res = []
    for (let i = 0; i < row; i++) {
        let min = Number.MAX_VALUE, index = 0, max = Number.MIN_SAFE_INTEGER
        for (let j = 0; j < col; j++) {
            if (matrix[i][j] < min) {
                min = matrix[i][j]
                index = j
            }
        }

        for (let m = 0; m < row; m++) {
            if (matrix[m][index] > max) {
                max = matrix[m][index]
            }
        }

        if (min === max) {
            res.push(min)
        }

    }

    return res
};
/* 模拟 */
var luckyNumbers = function (matrix) {
    const m = matrix.length, n = matrix[0].length
    const ret = []

    for (let i = 0; i < m; i++) {
        for (let j = 0; j < n; j++) {
            let isMin = true, isMax = true
            for (let k = 0; k < n; k++) {
                if (matrix[i][k] < matrix[i][j]) {
                    isMin = false
                    break
                }
            }
            if (!isMin) continue

            for (let k = 0; k < m; k++) {
                if (matrix[k][j] > matrix[i][j]) {
                    isMax = false
                    break
                }
            }

            if (isMax) ret.push(matrix[i][j])
        }
    }

    return ret
}

luckyNumbers([[7, 8], [1, 2]])